<?php

namespace App\Models\PersonInfoManagement;

use App\Models\Constant\Fields;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Temporary extends Model
{
    use SoftDeletes;
    static $SYSTEM = 'App\Models\SystemManagement';
    protected $table = 'temporaries';
    public $primaryKey = 'id';
    protected $guarded = ['temporary_ids'];

    protected $hidden = ['deleted_at','created_at','updated_at'];

    public function getList($request)
    {
        $per_page = $request->input('per_page',10);
        return self::orderBy('id','desc')
            ->with(['organization','department','post','skill','files'])
            ->paginate($per_page);
    }

    //所属组织
    public function organization()
    {
        return $this->belongsTo(self::$SYSTEM.'\Organization',Fields::ORGAN_ID,Fields::ID)->select('id','name');
    }

    //所属部门
    public function department()
    {
        return $this->belongsTo(self::$SYSTEM.'\Department',Fields::DEPART_ID,Fields::ID)->select('id','name');
    }

    //所属岗位
    public function post()
    {
        return $this->belongsTo(self::$SYSTEM.'\Post',Fields::POST_ID,Fields::ID)->select('id','name');
    }

    //所属岗位职级
    public function skill()
    {
        return $this->belongsTo(self::$SYSTEM.'\Skill',Fields::SKILL_ID,Fields::ID)->select('id','name');
    }

    public function files()
    {
        return $this->hasMany(TemporaryFile::class,'temporary_id')->with('file');
    }
}
